﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using QuickGraph;
using QuickGraph.Serialization;
using System.Xml.Serialization;

namespace SharedCongkak
{
    public class LevelData
    {

        //public List<AbstractHole> ListOfHoles;
        //[ContentSerializerIgnore]
        public List<Path> ListOfPaths;

        public AdjacencyGraph<AbstractHole, Path> ConvertToQuickGraph()
        {
            var output = new AdjacencyGraph<AbstractHole, Path>(false);
            output.EdgeAdded += (Path edge) => 
            {
                edge.Source.NextEdges.Add(edge);
                edge.Target.PrevEdges.Add(edge);
                edge.CreatePath();
            };

            //output.VertexAdded.
            if(ListOfPaths == null)
                return output;

            foreach (var path in ListOfPaths)
            {
                output.AddVerticesAndEdge(path);
            }
            return output;
        }



        public void FromQuickGraph(AdjacencyGraph<AbstractHole, Path> graph)
        {
            //ListOfHoles = new List<AbstractHole>(graph.Vertices);
            ListOfPaths = new List<Path>(graph.Edges);
        }
    }

    public class LevelDataReader : ContentTypeReader<LevelData>
    {
        protected override LevelData Read(
                ContentReader input,
                LevelData existingInstance)
        {

            LevelData levelData = new LevelData();

            //levelData.ListOfHoles = input.ReadObject<List<AbstractHole>>();
            levelData.ListOfPaths = input.ReadObject<List<Path>>();

            return levelData;
        }
    }
}
